package www.lagou.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import www.lagou.entity.Transaction;
import www.lagou.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Transaction数据操作
 *
 * @author Shuxian Huang
 */
public class TransactionDao {

    /**
     * 插入一条交易记录
     * @param transaction
     * @return
     */
    public int insertTransaction(Connection con, Transaction transaction) throws SQLException {

        //1、创建QueryRunner
        QueryRunner qr = new QueryRunner();

        //2、编写sql语句
        String sql = "insert into transaction values (?,?,?,?,?)";

        //3、执行sql
        return qr.update(con, sql, transaction.getId(), transaction.getCardId(),
                transaction.getTraType(), transaction.getTraMoney(), transaction.getTraDate());

    }
}
